#!/bin/bash
set -e 
DIR="$(cd "$(dirname "$0")" && pwd)"
source $DIR/common.sh

set +o noglob
# 关闭和禁用防火墙
h2 "[Step $item]: stop firewalld ..."; let item+=1
systemctl stop firewalld
h2 "[Step $item]: disable firewalld ..."; let item+=1
systemctl disable firewalld
h2 "[Step $item]: stop selinux perpetual ..."; let item+=1
# setenforce 0 临时关闭
sed -i 's/enforcing/disabled/' /etc/selinux/config
h2 "[Step $item]: stop swap perpetual ..."; let item+=1
# swapoff -a 临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab
# 添加各个节点的解析，IP 地址需要替换为你自己服务器的内网 IP 地址。
h2 "[Step $item]: Hostname DNS resolution  ..."; let item+=1
cat >> /etc/hosts << EOF
192.168.72.100 k8s-master
192.168.72.101 k8s-worker1
192.168.72.102 k8s-worker2
EOF
# 时间同步
h2 "[Step $item]: download wlnmp rpm  ..."; let item+=1
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
h2 "[Step $item]: install wlnmp  ..."; let item+=1
yum install -y  wntp
h2 "[Step $item]: install ntpdate  ..."; let item+=1
yum install -y ntpdate
h2 "[Step $item]: time lock for aliyun  ..."; let item+=1
ntpdate -u ntp1.aliyun.com
# 修改 Linux 内核参数，添加网桥过滤和地址转发功能
h2 "[Step $item]: configure network  ..."; let item+=1
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
h2 "[Step $item]: enable configuration  ..."; let item+=1
sudo sysctl --system
